<template>
  <div>
    <h2>我是父组件</h2>
    <Soncomp
      v-for="item in message"
      :key="item.id"
      :msg="item"
      @oneyear="year"
    />
  </div>
</template>

<script>
import Soncomp from './SonComponent.vue'
export default {
  name: 'FatherComponent',
  components: {
    Soncomp,
  },
  data() {
    return {
      message: [
        {
          id: '1',
          uname: 'harry',
          age: 28,
          profess: '前端',
        },
        {
          id: '2',
          uname: '豪哥',
          age: 21,
          profess: '测试',
        },
        {
          id: '3',
          uname: '嘉哥',
          age: 21,
          profess: '全栈',
        },
        {
          id: '4',
          uname: '翔哥',
          age: 18,
          profess: '后端',
        },
      ],
    }
  },

  methods: {
    year(one, id) {
      this.message.forEach((item) => {
        if (item.id === id) {
          item.age += one
        }
      })
    },
  },
}
</script>

<style scoped></style>
